package com.placedial;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;

public class Helper {
	
    public GraphP copy(GraphP p){
    	//destinate
    	Set vset=new HashSet();
    	Set cset=new HashSet();
    	int k=0;
    	int size=0;
    	HashMap graph=new HashMap();
		
		
		//source
		Set sVset=p.getVertexset();
		Set sCset=p.getCoverSet();
		int sk=p.getK();
		int sSize=p.getSize();
		HashMap sgraph=p.getGraph();
		
          //copy 
	    vset=this.copySet(sVset);
	    cset=this.copySet(sCset);
	    k=sk;
	    size=sSize;
	    graph=this.copymap(sgraph);
	
		GraphP copy=new GraphP(vset,cset,k,size,graph);
    	 return copy;

    }
	
	public Set copySet(Set s){
		Set copy=new HashSet();
	    
	    if(s!=null&&!s.isEmpty()){
	    	for(Object o: s){
	    		
	    		copy.add(o);
	    	}
	    }
	    return copy;
	}
	
	public HashMap copymap(HashMap map){
		HashMap copy=new HashMap();
		
		if(map!=null&&!map.isEmpty()){
		
		 Set entrySet=map.entrySet();
		 
		 Set copye=this.copySet(entrySet);
		 Iterator it=copye.iterator();
		 while(it.hasNext()){
			 Entry e=(Entry) it.next();
			 HashSet value=(HashSet) this.copySet((Set)e.getValue());
			 
			 copy.put(e.getKey(), value);
		 }
		}
		return copy;
		
	}

}
